/*
 * IDData.h
 *
 *  Created on: Jul 8, 2011
 *      Author: matthew
 */

#ifndef IDDATA_H_
#define IDDATA_H_

#include <vector>
#include <string>
#include "PayloadData.h"


using namespace std;

template<class T> class CIDData {
		vector<CPayloadData<T> > *pData;
		string *pstrID;
		static const unsigned int nReserveMultiple = 10000;
	public:
		CIDData();
		CIDData(string);
		CIDData(string, float, vector<T>);
		CIDData(CIDData<T> const &);
		CIDData<T>& operator=(CIDData<T> const &);
		~CIDData();

		void SetID(string);
		string GetID();
		void AddData(float, vector<T>);
		float GetTimestamp(unsigned int);
		void SetTimestamp(unsigned int, float);
		vector<T> GetData(unsigned int);
		unsigned int GetNumOfDataPayloads();
};

template<class T> CIDData<T>::CIDData(){
	pData = new vector<CPayloadData<T> >;
	pData->reserve(this->nReserveMultiple);
	pstrID = new string("");
}

template<class T> CIDData<T>::CIDData(string strNewID){
	pData = new vector<CPayloadData<T> >;
	pData->reserve(this->nReserveMultiple);
	pstrID = new string(strNewID);
}

template<class T> CIDData<T>::CIDData(string strID, float fTime, vector<T> data){
	pData = new vector<CPayloadData<T> >;
	pData->reserve(this->nReserveMultiple);
	pData->push_back(CPayloadData<T>(fTime, data));
	pstrID = new string(strID);
}

template<class T> CIDData<T>::CIDData(CIDData<T> const &rhs){
	pData = new vector<CPayloadData<T> > (*(rhs.pData));
	pstrID = new string (*(rhs.pstrID));
}

template<class T> CIDData<T>& CIDData<T>::operator=(CIDData<T> const &rhs){
	if (this != &rhs)
	{
		delete pData;
		delete pstrID;
		pData = new vector<CPayloadData<T> > (*(rhs.pData));
		pstrID = new string (*(rhs.pstrID));
	}
	return *this;
}

template<class T> CIDData<T>::~CIDData(){
	delete pData;
	delete pstrID;
}

template<class T> void CIDData<T>::SetID(string strID){
	pstrID->assign(strID);
}

template<class T> string CIDData<T>::GetID(){
	return *pstrID;
}

template<class T> void CIDData<T>::AddData(float nTime, vector<T> data){
	if (pData->capacity() == pData->size())
		pData->reserve(pData->size() + this->nReserveMultiple);
	pData->push_back(CPayloadData<T>(nTime, data));
}

template<class T> float CIDData<T>::GetTimestamp(unsigned int nIndex){
	if (nIndex < pData->size())
		return pData->at(nIndex).GetTimestamp();
	else
		return 0.0;
}

template<class T> void CIDData<T>::SetTimestamp(unsigned int nIndex, float fTime){
	if (nIndex < pData->size())
		pData->at(nIndex).SetTimestamp(fTime);
}

template<class T> vector<T> CIDData<T>::GetData(unsigned int nIndex){
	if (nIndex < pData->size())
		return pData->at(nIndex).GetData();
	else
		return vector<T>(0,0);
}

template<class T> unsigned int CIDData<T>::GetNumOfDataPayloads(){
	return pData->size();
}

#endif /* IDDATA_H_ */
